package com.wolf.etl.service.impl;

import com.wolf.etl.model.EtlTransformFieldTypeModel;
import com.wolf.etl.service.IEtlTransformFieldTypeService;
import com.wolf.provider.order.enumerate.QUERY_TYPE;
import com.wolf.provider.order.info.PageBean;
import com.wolf.provider.order.info.PageInfo;
import com.wolf.provider.order.info.ParamBean;
import com.wolf.provider.order.service.impl.BaseServiceImpl;
import com.wolf.util.NumberUtil;
import com.wolf.vo.PageResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author sdyang
 * @date 2019/10/13 15:43
 **/
@Service("etl_transform_field_type_service")
public class EtlTransformFieldTypeServiceImpl extends BaseServiceImpl<Long> implements IEtlTransformFieldTypeService {
    private static Logger logger = LoggerFactory.getLogger(EtlDefineServiceImpl.class);

    private static final String logger_prefix = "wolf-etl#com.wolf.etl.service.impl#EtlTransformFieldTypeServiceImpl";

    @Override
    public List<EtlTransformFieldTypeModel> findByDialect(String dialect) {
        StringBuilder sql = new StringBuilder("SELECT * from etl_transform_field_type where 1=1 and status=1 and dialect=").append(dialect);
        Map<String,Object> map = new HashMap<>();

        List<EtlTransformFieldTypeModel> vos = findModelListByMap(sql.toString(), map, new EtlTransformFieldTypeModel());

        return vos;
    }

    @Override
    public PageResult<EtlTransformFieldTypeModel> findByPage(EtlTransformFieldTypeModel model, PageBean pageBean) {
        StringBuilder sql = new StringBuilder();
        sql.append(" select * from etl_transform_field_type t where 1=1 ");

        List<ParamBean> paramBeans = new ArrayList<ParamBean>();

        if (NumberUtil.isNotEmpty(model.getClient_id())) {
            ParamBean paramBean = new ParamBean();
            paramBean.setWhereField("t.client_id");
            paramBean.setField("client_id");
            paramBean.setValue(model.getClient_id());
            paramBean.setType(QUERY_TYPE.EQUAL.getType());
            paramBeans.add(paramBean);
        }

        PageInfo<EtlTransformFieldTypeModel> vos = findByPageInfo(sql.toString(), paramBeans, model, pageBean);

        PageResult result = new PageResult();
        result.buildResult(vos);
        return result;
    }
}
